@extends('admin/layout.app')

@section('title', '菜单编辑')

@section('content')
    @if (count($errors) > 0)
        <div class="col-lg-9">
            <div class="alert alert-danger">
                <ul>
                    @if(is_object($errors))
                        @foreach($errors->all() as $error)
                            <li>{{$error}}</li>
                        @endforeach
                    @else
                        <li>{{$errors}}</li>
                    @endif
                </ul>
            </div>
        </div>
    @endif
    <div class="col-lg-10">
        @if($menu_info)
            <form class="form-horizontal" action="/admin/menu/{{$menu_info['id']}}" method="post">
                <input type="hidden" name="_method" value="put">
                {{csrf_field()}}
                <div class="form-group">
                    <label for="inputPassword3" class="col-sm-2 control-label">上级</label>
                    <div class="col-sm-8">
                        <select class="form-control" name="parent_id">
                            <option value="0">作为一级菜单</option>
                            @if($menu_list)
                                @foreach($menu_list as $item)
                                    @if($menu_info['parent_id'] == 0)
                                        <option value="{{$item['id']}}">{{ str_repeat('&nbsp;&nbsp;|--',$item['level']).$item['name'] }}</option>
                                    @else
                                        <option value="{{$item['id']}}"  {{ $menu_info['parent_id'] == $item['id'] ? 'selected' : '' }}>{{ str_repeat('&nbsp;&nbsp;|--',$item['level']).$item['name'] }}</option>
                                    @endif
                                @endforeach
                            @endif
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label for="input-name" class="col-sm-2 control-label">菜单名称</label>
                    <div class="col-sm-8">
                        <input type="text" name="name" class="form-control" id="input-name" placeholder="菜单名称"
                               value="{{$menu_info['name']}}">
                    </div>
                </div>
                <div class="form-group">
                    <label for="input-url" class="col-sm-2 control-label">链接地址</label>
                    <div class="col-sm-8">
                        <input type="text" name="url" class="form-control" id="input-url" placeholder="链接地址,父级菜单不需要填写"
                               value="{{$menu_info['url']}}">
                    </div>
                </div>
                <div class="form-group">
                    <label for="input-route" class="col-sm-2 control-label">路由名称</label>
                    <div class="col-sm-8">
                        <input type="text" name="route_name" class="form-control" id="input-route" placeholder="路由名称，开发人员填入"
                               value="{{$menu_info['route_name']}}">
                    </div>
                </div>
                <div class="form-group">
                    <label for="input-remark" class="col-sm-2 control-label">备注</label>
                    <div class="col-sm-8">
                        <textarea class="form-control" name="remark">{{$menu_info['remark']}}</textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label for="input-status" class="col-sm-2 control-label">状态</label>
                    <div class="col-sm-8">
                        <p class="pt6pr12">
                            <input id="input-status-1" type="radio" name="status"
                                   value="1" {{ $menu_info['status'] == 1 ? 'checked' : '' }}/> <label
                                    for="input-status-1">正常</label>
                            <input id="input-status-2" type="radio" name="status"
                                   value="2" {{ $menu_info['status'] == 2 ? 'checked' : '' }}/> <label
                                    for="input-status-2">禁用</label>
                        </p>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-3 col-sm-10">
                        <button type="submit" class="btn btn-default">保存</button>
                    </div>
                </div>
            </form>
        @else
            <p>用户id不存在，请重新访问</p>
        @endif
    </div>
@endsection
